package com.ruoyi.web.controller.bus.controller;

import com.ruoyi.bus.domain.BusFactor;
import com.ruoyi.bus.dto.BusDataParam;
import com.ruoyi.bus.service.IBusFactorService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-09-10
 */
@Controller
@RequestMapping("/bus/factor")
public class BusFactorController extends BaseController
{
    private String prefix = "bus/factor";

    @Autowired
    private IBusFactorService busFactorService;

    @RequiresPermissions("bus:factor:view")
    @GetMapping()
    public String factor()
    {
        return prefix + "/factor";
    }

    @RequiresPermissions("bus:factor:view")
    @GetMapping("/dayReport")
    public String dayReport()
    {
        return prefix + "/dayReport";
    }

    @GetMapping("/monthReport")
    public String monthReport()
    {
        return prefix + "/monthReport";
    }

//    @RequiresPermissions("bus:factor:busData")
    @PostMapping("/busData")
    @ResponseBody
    public TableDataInfo busData(@RequestBody BusDataParam busDataParam,Model model)
    {
        startPage();
        List<BusFactor> busFactors = busFactorService.selectBusData(busDataParam.getMonitorId(), busDataParam.getProduceTime(), busDataParam.getList());
        model.addAttribute("busFactors",busFactors);
        System.out.println(busFactors);
        return getDataTable(busFactors);
    }

    @PostMapping("/busDataTest")
    @ResponseBody
    public TableDataInfo busDataTest(@RequestBody BusDataParam busDataParam)
    {
        startPage();
        List<BusFactor> busFactors = busFactorService.selectBusData(busDataParam.getMonitorId(), busDataParam.getProduceTime(), busDataParam.getList());
        return getDataTable(busFactors);
    }



    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("bus:factor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusFactor busFactor)
    {
        startPage();
        List<BusFactor> list = busFactorService.selectBusFactorList(busFactor);
        return getDataTable(list);
    }

    /**
     * 查询【请填写功能名称】
     */
    @RequestMapping("/list/{monitorId}")
    @ResponseBody
    public List<BusFactor> listMonitorId(@PathVariable("monitorId") Long monitorId)
    {
        List<BusFactor> list = busFactorService.selectBusFactorByMonitorId(monitorId);
        return list;
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("bus:factor:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusFactor busFactor)
    {
        List<BusFactor> list = busFactorService.selectBusFactorList(busFactor);
        ExcelUtil<BusFactor> util = new ExcelUtil<BusFactor>(BusFactor.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("bus:factor:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusFactor busFactor)
    {
        return toAjax(busFactorService.insertBusFactor(busFactor));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{factorId}")
    public String edit(@PathVariable("factorId") Long factorId, ModelMap mmap)
    {
        BusFactor busFactor = busFactorService.selectBusFactorByFactorId(factorId);
        mmap.put("busFactor", busFactor);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("bus:factor:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusFactor busFactor)
    {
        return toAjax(busFactorService.updateBusFactor(busFactor));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("bus:factor:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(busFactorService.deleteBusFactorByFactorIds(ids));
    }
}
